<template>
	<view class="root"></view>
</template>

<script lang="ts">
	import { Storage } from "@/libs/utils";
	import Vue from "vue";
	import Component from "vue-class-component";

	@Component
	export default class Pay extends Vue {
		// component property
		onLoad({ id }: AnyObject) {
			this.$request
				.get("&r=order.pay.new_hair_pay", {
					id,
					comefrom: "wxapp",
					openid: Storage.get("authorization"),
				})
				.then((res) => {
					uni.requestPayment({
						...res.wechat.payinfo,
						success: (res) => {
							uni.redirectTo({
								url: `/pages/common/Webview?url=${encodeURIComponent(
									"https://jiafa.chengshikuxi.site/app/index.php?i=1&c=entry&m=ewei_shopv2&do=mobile&r=order.index"
								)}`,
							});
						},
						fail() {
							uni.showToast({ title: "支付失败", icon: "none" });
							uni.redirectTo({
								url: `/pages/common/Webview?url=${encodeURIComponent(
									"https://jiafa.chengshikuxi.site/app/index.php?i=1&c=entry&m=ewei_shopv2&do=mobile&r=order.index"
								)}`,
							});
						},
					});
				});
		}
	}
</script>

<style lang="scss" scoped>
	// scss
</style>